package com.bush.mall.product.controller;

import org.springframework.web.bind.annotation.*;
import com.bush.mall.common.entity.Result;
import com.bush.mall.product.entity.CategoryEntity;
import com.bush.mall.product.service.CategoryService;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 商品分类
 * @author RUN
 * @date 2022-11-28
 */
@RestController
@RequestMapping("product/category")
@Api(tags = "商品分类管理" )
public class CategoryController {

    @Resource(name= CategoryService.BEAN_ID)
    private CategoryService categoryService;

    @ApiOperation(value = "树形查找分类列表")
    @GetMapping("tree")
    public Result tree(){
        return categoryService.tree();
    }

    @ApiOperation(value = "根据商品类别id查询")
    @GetMapping("{id}")
    public Result queryByCategoryId(@PathVariable("id") Long id){
        return categoryService.queryByCategoryId(id);
    }

    @ApiOperation(value = "保存商品分类")
    @PostMapping
    public Result saveCategory(@RequestBody CategoryEntity category){
        return categoryService.saveCategory(category);
    }

    @ApiOperation(value = "修改商品分类")
    @PutMapping
    public Result updateCategory(@RequestBody CategoryEntity category){
        return categoryService.updateCategory(category);
    }

    @ApiOperation("获取商品指定三层分类")
    @GetMapping("three/{id}")
    public Result three(@PathVariable Long id){
        return categoryService.three(id);
    }

    @ApiOperation(value = "通过指定id删除商品分类")
    @DeleteMapping("{id}")
    public Result deleteCategory(@PathVariable(value = "id") Long id){
        return categoryService.deleteCategory(id);
    }

    @ApiOperation(value = "通过指定ids批量删除商品分类")
    @DeleteMapping("batch")
    public Result deleteBatchCategory(@RequestBody List<Long> ids){
        return categoryService.deleteBatchCategory(ids);
    }

}
